package com.project.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.RoleBean;
import com.project.mapper.IRoleMapper;
import com.project.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class RoleServiceImpl implements IRoleService{
    @Autowired
    private IRoleMapper mapper;

    @Override
    public IPage<RoleBean> cutAll(int pageNO) {
        return mapper.selectPage(
                new Page<RoleBean>(pageNO,PAGESIZE),null
        );
    }

    @Override
    public List<RoleBean> findAll() {
        return mapper.selectList(null);
    }

    @Override
    public void add(RoleBean role, int[] gradeArray) {
        mapper.insert(role);
        mapper.addGradeList(role.getId(),gradeArray);


    }

    @Override
    public RoleBean findById(int id) {
      RoleBean roleBean=  mapper.selectById(id);

      roleBean.setGradeList(mapper.findByRoleId(id));

        return roleBean;
    }

    @Override
    public void updateGrade(int id, int[] gradeArray) {
        mapper.updateGrade(id,gradeArray);

    }

    @Override
    public void del(int id) {
        mapper.del(id);

    }
}
